﻿@model EditViewModel
@{
  ViewData["Title"] = "学生信息编辑";
  var avatarPath = "~/images/" + (Model.EditAvatarPath ?? "photo.webp");

}

<form enctype="multipart/form-data" asp-controller="Home" asp-action="Edit" method="post" class="mt-3">
  <input hidden asp-for="Id"/>
  <input hidden  asp-for="EditAvatarPath"/>
  <div asp-validation-summary="All" class="text-danger"></div>
  <div class="form-group row">
    <label asp-for="Name" class="col-sm-2 col-form-label"></label>
    <div class="col-sm-10">
      <input asp-for="Name" class="form-control" placeholder="请输入名字" />
      <span asp-validation-for="Name" class="text-danger"></span>
    </div>
  </div>
  <div class="form-group row">
    <label asp-for="Email" class="col-sm-2 col-form-label"></label>
    <div class="col-sm-10">
      <input asp-for="Email" class="form-control" placeholder="请输入邮箱" />
      <span asp-validation-for="Email" class="text-danger"></span>
    </div>
  </div>
  <div class="form-group row">
    <label asp-for="ClassName" class="col-sm-2 col-form-label"></label>
    <div class="col-sm-10">
      <select asp-for="ClassName" asp-items="Html.GetEnumSelectList<ClassNameEnum>()" class="custom-select mr-sm-2">
        <option value="">请选择</option>
      </select>
      <span asp-validation-for="ClassName" class="text-danger"></span>
    </div>
  </div>
  <div class="form-group row">
    <label asp-for="Avatar" class="col-sm-2 col-form-label"></label>
    <div class="col-sm-10">
      <div class="custom-file">
        <input asp-for="Avatar" class="form-control custom-file-input" multiple />
        <label class="custom-file-label">请选择照片</label>
      </div>
    </div>
  </div>
  <div  style="text-align:center">
    <img src="@avatarPath" alt="头像" asp-append-version="true" />
  </div>

  <button type="submit" class="btn-primary btn">跟新</button>
</form>

@section Scripts{
  <script type="text/javascript">
    $(document).ready(function () {
      $(".custom-file-input").on("change", function () {
       @* var fileName = $(this).val().split("\\").pop();
        $(this).next(".custom-file-label").html(fileName);*@
        var fileLabel = $(this).next(".custom-file-label");
        var files = $(this)[0].files;
        if (files.length > 1) {
          fileLabel.html("您已选择了：" + files.length + "个文件");
        } else if (files.length == 1) {
          fileLabel.html(files[0].name);
        }
      })
    })
  </script>
}

